home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / C / hello.c < prev    next >
C/C++ Source or Header  |  1985-10-30  |  5KB  |  137 lines

  1. /* From eric@topaz.RUTGERS.EDU (Eric Lavitsky) Wed Sep  4 15:12:41 1985 */
  2.  
  3. /*
  4.  
  5.  Well here is the first ever Amiga source to be posted on the net. The
  6. following code was taken from the Amiga User Interface Manual. This
  7. program uses the Intuition user interface under V28 of the operating
  8. system. Intuition controls all the window sizing and dragging for the
  9. application, though you can tell Intuition to tell your program about
  10. certain events (like resizing) so you can take your own action. The
  11. code is not ultimately clean - all the structures could be initialized 
  12. like the first one etc. I kept most of the original comments from the
  13. example and added one or two of my own.
  14.  
  15.  The program opens its own screen (320x200) and creates a window that
  16. can be dragged, sized, pushed up or down and closed. The screen can also
  17. be pushed down or popped up and be pulled down to reveal the screen below
  18. it (one of my favorite features!)
  19.  
  20. */
  21.  
  22. /***************************************************************************
  23.  *
  24.  *       "Hello World"
  25.  *
  26.  **************************************************************************/
  27.  
  28. #include <exec/types.h>
  29. #include <intuition/intuition.h>
  30. #include <intuition/intuitionbase.h>
  31.  
  32. struct IntuitionBase *IntuitionBase;
  33. struct GfxBase *GfxBase;
  34.  
  35. #define INTUITION_REV 28        /* You must be sure this is correct */
  36. #define GRAPHICS_REV 28
  37.  
  38. /* This font declaration will be used for our new screen */
  39.  
  40. struct TextAttr MyFont =
  41.    {
  42.    "topaz.font",     /* Font Name *
  43.    TOPAZ_SIXTY,      /* Font Height */
  44.    FS_NORMAL,        /* Style */
  45.    FPF_ROMFONT       /* Preferences */
  46.    };
  47.  
  48. /* This is the declaration of a pre-initialized NewScreen data block.
  49.  * It often requires less work, and often uses less code space, to
  50.  * pre-initialize data structures in this fashion.
  51.  */
  52.  
  53. struct NewScreen NewScreen =
  54.    {
  55.    0,                /* the LeftEdge should be equal to zero */
  56.    0,                /* TopEdge */
  57.    320,              /* Width (lo-resolution) */
  58.    200,              /* Height (non-interlace) */
  59.    2,                /* Depth (16 colors will be available) */
  60.    0, 1,             /* the DetailPen and BlockPen specifications */
  61.    NULL,             /* no special display modes */
  62.    CUSTOMSCREEN,     /* the Screen Type */
  63.    &MyFont,          /* Use my own font */
  64.    "My Own Screen",  /* this declaration is compiled as a text pointer */
  65.    NULL,             /* no special Screen Gadgets */
  66.    NULL              /* no special Custom BitMap */
  67.    };
  68.  
  69. main()
  70. {
  71.    struct Screen *Screen;
  72.    struct NewWindow NewWindow;
  73.    struct Window *Window;
  74.  
  75.    /* Open the Intuition library. The result returned by this call is
  76.     * used to connect your program to the actual Intuition routines
  77.     * in ROM. If the result of this call is zero, something is wrong
  78.     * and the Intuition you requested is not available, so your program
  79.     * should exit immediately
  80.     */
  81.  
  82.    IntuitionBase = (struct IntuitionBase *)
  83.       OpenLibrary("intuition.library",INTUITION_REV);
  84.    if(IntuitionBase == NULL)
  85.       exit(FALSE);
  86.  
  87.    GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",GRAPHICS_REV);
  88.    if(GfxBase == NULL)
  89.       exit(FALSE);
  90.  
  91.    if((Screen = (struct Screen *) OpenScreen(&NewScreen)) == NULL)
  92.       exit(FALSE);
  93.  
  94.    /* Initialize the NewWindow structure for the call to OpenWindow() */
  95.  
  96.    NewWindow.LeftEdge = 20;
  97.    NewWindow.TopEdge = 20;
  98.    NewWindow.Width = 300;
  99.    NewWindow.Height = 100;
  100.    NewWindow.DetailPen = 0;
  101.    NewWindow.BlockPen = 1;
  102.    NewWindow.Title = "A Simple Window";
  103.    NewWindow.Flags = WINDOWCLOSE | SMART_REFRESH | ACTIVATE
  104.       | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH;
  105.    NewWindow.IDCMPFlags = CLOSEWINDOW;  /* Tell us about CLOSEWINDOW events */
  106.    NewWindow.Type = CUSTOMSCREEN;
  107.    NewWindow.FirstGadget = NULL;
  108.    NewWindow.CheckMark = NULL;
  109.    NewWindow.Screen = Screen;
  110.    NewWindow.BitMap = NULL;
  111.    NewWindow.MinWidth = 100;
  112.    NewWindow.MinHeight = 25;
  113.    NewWindow.MaxWidth = 32767;
  114.    NewWindow.MaxHeight = 32767;
  115.  
  116.    /* Try to open the window. Like the call to OpenLibrary(), if
  117.     * the OpenWindow call is successful, it returns a pointer to
  118.     * the structure for your new window. If the OpenWindow() call
  119.     * fails, it returns a zero.
  120.     */
  121.  
  122.    if(( Window = (struct Window *) OpenWindow(&NewWindow)) == NULL)
  123.       exit(FALSE);
  124.  
  125.    Move(Window->RPort,20,20);
  126.    Text(Window->RPort,"Hello World",11);
  127.  
  128.    for(;;)
  129.      {
  130.      Wait(1 << Window->UserPort->mp_SigBit);
  131.      CloseWindow(Window);       /* Close the Window */
  132.      CloseScreen(Screen);       /* Close the Screen */
  133.      exit(TRUE);                /* Exit */
  134.      }
  135. }
  136.                                          
  137.